package lch.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import lch.entity.PageResult;
import lch.entity.QueryPageBean;
import lch.entity.Result;
import lch.service.OrderListService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author lch
 * @date 2020-01-16 16:40
 */

@RestController
@RequestMapping("/orderList")
public class OrderListController {

    @Reference
    private OrderListService orderListService;

    /**
     *
     * 分页列表
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findList")
    public PageResult findList(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = orderListService.findList(queryPageBean);
        return pageResult;
    }

    /**
     * 预约列表添加
     * @param map
     * @return
     */
    @RequestMapping("/addList")
    public Result addList(@RequestBody Map map) {
        try {
            orderListService.addList(map);
            return new Result(true, "添加预约列表成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "添加预约列表失败");
        }
    }

    /**
     * 编辑回显选中预约列表项
     * @param id
     * @return
     */
    @RequestMapping("/findById")
    public Result findById(Integer id) {
        try {
            Map map = orderListService.findById(id);
            return new Result(true, "数据回显成功", map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "数据回显失败");
        }
    }

    /**
     * 编辑（修改）预约列表项
     * @param map
     * @return
     */
    @RequestMapping("/editList")
    public Result editList(@RequestBody Map map) {
        try {
            orderListService.editList(map);
            return new Result(true, "预约列表编辑项功能成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "预约列表编辑项功能失败");
        }
    }

    /**
     * 删除预约列表项
     * @param id
     * @return
     */
    @RequestMapping("/deleteById")
    public Result deleteById(Integer id) {
        try {
            orderListService.deleteById(id);
            return new Result(true, "删除预约列表项成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "删除预约列表项失败");
        }
    }
}